package com.yufeng.collaboration.controller;

import com.yufeng.collaboration.entity.Document;
import com.yufeng.collaboration.service.DocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/documents")
public class DocumentController {

    @Autowired
    private DocumentService documentService;

    @GetMapping("/group/{groupId}")
    public List<Document> getDocumentsByGroupId(@PathVariable Integer groupId) {
        return documentService.getDocumentsByGroupId(groupId);
    }


    @GetMapping("/{id}")
    public Document getDocumentById(@PathVariable Integer id) {
        return documentService.getDocumentById(id);
    }


    @PostMapping
    public void createDocument(@RequestBody Document document) {
        documentService.createDocument(document);
    }

    @PutMapping
    public void updateDocument(@RequestBody Document document) {
        documentService.updateDocument(document);
    }

    @DeleteMapping("/{id}")
    public void deleteDocument(@PathVariable Integer id) {
        documentService.deleteDocument(id);
    }
}